#include "UDPPort.h"

class TestHandler: public PortHandler
{
public:
    void handleReceive(ByteBuffer* data)
    {
        SocketAddress* p_sa = (SocketAddress*)data->getParam();
        std::cout<<p_sa->toString()<<std::endl;
        delete p_sa;
        std::cout<<"recv:"<<data->Length();
        data->decreaseRef();
    }
    void handleTimer(EventNotification* event)
    {
        event->release();
    }
};


int main()
{
    SocketReactor reactor;
    reactor.setTimeout(Poco::Timespan(1,0,0,0,0));

    ByteBufferPool bpool;
    bpool.init(10, 200);

    //SocketAddress stunSa("192.168.1.99","3478");
    SocketAddress stunSa("stun.l.google.com","19302");

    SocketAddress la("192.168.1.99", 800);

    IPAddress ip("192.168.1.99");

    UDPPort port(reactor, &bpool);

    TestHandler hdlr;

    port.registerHandler(&hdlr);

   // port.setup(la);
     port.setup(ip);

    std::cout<< port.getAddress().toString();

    reactor.run();

    return 0;
}